package controllers

import (
	"encoding/json"
	"server/enity"
	"server/global"
	"server/logic"
	"server/models"
	"strconv"
)

/*
Date:2021/11/20
Time:10:47 下午
*/

type UserController struct {
	BaseController
}

func (c *UserController) AddNurse() {
	param := new(enity.NurseReq)
	err := json.Unmarshal(c.apiData, param)
	if err != nil {
		c.FailReturn(global.NewCodeError(40000))
	}
	c.HandError(logic.NurseLogicInstance.AddNurse(param))
	c.SuccReturn("ok")
}

func (c *UserController) UpdateNurse() {
	param := new(enity.NurseReq)
	id, _ := c.GetInt("id", 0)
	err := json.Unmarshal(c.apiData, param)
	if err != nil {
		c.FailReturn(global.NewCodeError(40000))
	}
	c.HandError(logic.NurseLogicInstance.UpdateNurse(id, param))
	c.SuccReturn("ok")
}

func (c *UserController) DelNurse() {
	id := c.Ctx.Input.Param(":id")
	idInt, _ := strconv.Atoi(id)
	c.HandError(models.NewNurse().Del(idInt))
	c.SuccReturn("ok")
}
func (c *UserController) GetNurses() {
	list, err := models.NewNurse().GetList()
	c.HandError(err)
	c.SuccReturn(list)
}
